Cancelled
Push — master ( 28a5cf...9e6262 )
by Paul
06:07
created

GLSR.postAjax   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 2
b 0
f 0
1
GLSR.colorControls = function()
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
{
3
	if( typeof x.wp !== 'object' || typeof x.wp.wpColorPicker !== 'function' )return;
0 ignored issues
show
Bug introduced by
The variable x seems to be never declared. If this is a global, consider adding a /** global: x */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4
5
	x( document ).find( 'input[type="text"].color-picker-hex' ).each( function() {
6
		var t = x( this );
7
		var options = t.data( 'colorpicker' ) || {};
8
		t.wpColorPicker( options );
9
	});
10
};
11
12
GLSR.dismissNotices = function()
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
13
{
14
	x( '.notice.is-dismissible' ).each( function() {
15
		var notice = x( this );
16
		notice.fadeTo( 100, 0, function() {
17
			notice.slideUp( 100, function() {
18
				notice.remove();
19
			});
20
		});
21
	});
22
};
23
24
GLSR.getURLParameter = function( name )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
{
26
	return decodeURIComponent(
27
		(new RegExp( '[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)' ).exec( location.search ) || [null, ''])[1].replace( /\+/g, '%20' )
28
	) || null;
29
};
30
31
GLSR.insertNotices = function( notices )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
{
33
	if( !notices )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
34
	if( !x( '#glsr-notices' ).length ) {
35
		x( '#message.notice' ).remove();
36
		x( 'form#post' ).before( '<div id="glsr-notices" />' );
37
	}
38
	x( '#glsr-notices' ).html( notices );
39
	x( document ).trigger( 'wp-updates-notice-added' );
40
};
41
42
GLSR.isUndefined = function( value )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
43
{
44
	return value === void(0);
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
45
};
46
47
GLSR.onChangeStatus = function( ev )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
48
{
49
	var post_id = this.href.match(/post=([0-9]+)/)[1];
50
	var status  = this.href.match(/action=([a-z]+)/)[1];
51
52
	if( GLSR.isUndefined( status ) || GLSR.isUndefined( post_id ))return;
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
53
54
	var request = {
55
		action: 'change-review-status',
56
		status : status,
57
		post_id: post_id,
58
	};
59
60
	GLSR.postAjax( ev, request, function( response )
61
	{
62
		var el = x( ev.target );
63
		if( !response.class )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
64
		el.closest( 'tr' ).removeClass( 'status-pending status-publish' ).addClass( response.class );
65
		el.closest( 'td.column-title' ).find( 'strong' ).html( response.link );
66
	});
67
};
68
69
GLSR.onClearLog = function( ev )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
70
{
71
	var request = {
72
		action: 'clear-log',
73
	};
74
	GLSR.postAjax( ev, request, function( response )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
75
	{
76
		GLSR.insertNotices( response.notices );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
77
		x( '#log-file' ).val( response.logger );
78
	});
79
};
80
81
82
83
GLSR.pointers = function( pointer )
84
{
85
	x( pointer.target ).pointer({
86
		content: pointer.options.content,
87
		position: pointer.options.position,
88
		close: function() {
89
			x.post( ajaxurl, {
0 ignored issues
show
Bug introduced by
The variable x seems to be never declared. If this is a global, consider adding a /** global: x */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable ajaxurl seems to be never declared. If this is a global, consider adding a /** global: ajaxurl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
90
				pointer: pointer.id,
91
				action: 'dismiss-wp-pointer',
92
			});
93
		},
94
	})
95
	.pointer( 'open' )
96
	.pointer( 'sendToTop' );
97
98
	x( document ).on( 'wp-window-resized', function() {
99
		x( pointer.target ).pointer( 'reposition' );
100
	});
101
};
102
103
GLSR.postAjax = function( ev, request, callback )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
104
{
105
	ev.preventDefault();
106
	var el = x( ev.target );
107
	if( el.is( ':disabled' ))return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
108
	request.nonce = request.nonce || el.closest( 'form' ).find( '#_wpnonce' ).val();
109
	var data = {
110
		action: site_reviews.action,
0 ignored issues
show
Bug introduced by
The variable site_reviews seems to be never declared. If this is a global, consider adding a /** global: site_reviews */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
111
		request: request,
112
	};
113
	el.prop( 'disabled', true );
114
	x.post( site_reviews.ajaxurl, data, function( response ) {
0 ignored issues
show
Bug introduced by
The variable x seems to be never declared. If this is a global, consider adding a /** global: x */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
115
		if( typeof callback === 'function' ) {
116
			callback( response );
117
		}
118
		el.prop( 'disabled', false );
119
	});
120
};
121
122
GLSR.textareaResize = function( el )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
123
{
124
	var minHeight = 320;
125
	var textarea  = el[0];
126
127
	textarea.style.height = 'auto';
128
129
	textarea.style.height = textarea.scrollHeight > minHeight ?
130
		textarea.scrollHeight + 'px' :
131
		minHeight + 'px';
132
};
133